package utils;

import java.io.IOException;

import com.myTestProject.cn.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MyLaunchAcitivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);// 调用了父类的onCreate()方法
		// requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
		setContentView(R.layout.testing_layout);
		Button start = (Button) findViewById(R.id.start);
		final Button bt_phone = (Button) findViewById(R.id.bt_phone);
		final EditText et = (EditText) findViewById(R.id.et_userPhone);
		
		DataInit.init();// 启动测试前，创建测试报告文件和配置文件
		
		bt_phone.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				String number = et.getText().toString();
				
				if (number.length() == 11) {
					try {
						UserInfo_Properties.save(UserInfo_Properties.MANERGERTEACHER_PHONENUMBER, number);
					} catch (IOException e) {
						e.printStackTrace();
					}
					Toast.makeText(getApplicationContext(), "成功保存手机号码到文件，可以开始测试", Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(getApplicationContext(), "请输入手机号码", Toast.LENGTH_SHORT).show();
				}
			}
		});
		start.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				
				if (!UserInfo_Properties.getValue(UserInfo_Properties.MANERGERTEACHER_PHONENUMBER).isEmpty()) {
					
					String testNumber=UserInfo_Properties.getValue(UserInfo_Properties.MANERGERTEACHER_PHONENUMBER);
					Log.e(UserInfo_Properties.TAG, "当前测试账号为："+testNumber);
					Runtime run = Runtime.getRuntime();
					
					try {
						run.exec(UserInfo_Properties.LAUNCHER_CMD);
						Toast.makeText(getApplicationContext(), "启动测试,testNumber="+testNumber, Toast.LENGTH_SHORT).show();
					} catch (IOException e) {
						Toast.makeText(getApplicationContext(), "启动测试失败", Toast.LENGTH_SHORT).show();
					}
				}else{
					Toast.makeText(getApplicationContext(), "请输入或保存测试账号、 ", Toast.LENGTH_SHORT).show();
				}
			}
		});
	}
}
